home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _695A66BF294640E795D4FB046CA73AEA < prev    next >
Encoding:
Text File  |  2004-01-06  |  10.3 KB  |  397 lines

  1.  
  2.  
  3.  
  4. PlaceableExplo = {
  5.     type = "Trigger",
  6.  
  7.     Properties = {
  8.         DimX = 5,
  9.         DimY = 5,
  10.         DimZ = 5,
  11.         ScriptCommand="",
  12.         PlaySequence="",
  13.         dummyModel="Objects/Pickups/explosive/explosive_dummy.cgf",        --
  14.         fileModel="objects/pickups/explosive/explosive.cgf",            --
  15.         object_ModelDestroyed="",                                        --
  16.         
  17.         ExplosionEffect="",
  18.         ExplosionScale=1,
  19.         
  20.         countdown=10, -- '-1' to disable
  21.         explDamage = 100,
  22.         explRmin = 2.0,
  23.         explRmax = 20.5,
  24.         explRadius = 3,
  25.         explImpulsive_pressure = 200,
  26.         bInitiallyVisible=1,
  27.         bAutomaticPlaceable=1,
  28.         TextInstruction="",
  29.         bActive=1,
  30.     },
  31.  
  32.     --PHYSICS PARAMS
  33.     explosion_params = {
  34.         pos = nil,
  35.         damage = 100,
  36.         rmin = 2.0,
  37.         rmax = 20.5,
  38.         radius = 3,
  39.         impulsive_pressure = 200,
  40.         shooter = nil,
  41.         weapon = nil,
  42.     },
  43.  
  44.     countdown_step=0,
  45.  
  46.     Editor={
  47.         Model="Objects/Editor/T.cgf",
  48.     },    
  49.  
  50.     timing_soundfile = "SOUNDS/items/bombcount.wav",
  51.     timing_sound = nil,
  52. }
  53.  
  54.  
  55.  
  56.  
  57. -------------------------------------------------------------------------------
  58. function PlaceableExplo:LoadGeometry()
  59.     if(self.Properties.dummyModel~="")then
  60.         self:LoadObject(self.Properties.dummyModel,0,1);
  61.     end
  62.     if(self.Properties.fileModel~="")then
  63.         self:LoadObject(self.Properties.fileModel,1,1);
  64.     end
  65.     if(self.Properties.object_ModelDestroyed~="")then
  66.         self:LoadObject(self.Properties.object_ModelDestroyed,2,1);        
  67.     end
  68. end
  69.  
  70. -------------------------------------------------------------------------------
  71. function PlaceableExplo:RegisterStates()
  72.     self:RegisterState("placeable");        -- show dummy
  73.     self:RegisterState("notarmed");            -- show explosives not ticking, armable
  74.     self:RegisterState("armed");            -- show explosives ticking, disarmable
  75.     self:RegisterState("detonated");        -- detonated no visual
  76. end
  77.  
  78.  
  79. -------------------------------------------------------------------------------
  80. function PlaceableExplo:OnReset()
  81.     self:EnableUpdate(0);
  82.     self:TrackColliders(1);
  83.  
  84.     --if(self.Properties.bInitiallyVisible==1)then
  85.         self:GotoState("placeable");
  86.     --else
  87.     --    self:GotoState("detonated");    
  88.     --end
  89.     
  90. --    if ((self.Properties.object_ModelDestroyed ~="") and 
  91. --    (self.Properties.object_ModelDestroyed ~= self.CurrDestroyedModel)) then
  92. --        self.CurrDestroyedModel = self.Properties.object_ModelDestroyed;
  93. --        self:LoadObject(self.Properties.object_ModelDestroyed,1,1);
  94. --        self:DrawObject(1,0);
  95. --        self:CreateStaticEntity( 10,100 );
  96. --    end
  97.  
  98.     
  99.     local Min = { x=-self.Properties.DimX/2, y=-self.Properties.DimY/2, z=-self.Properties.DimZ/2 };
  100.     local Max = { x=self.Properties.DimX/2, y=self.Properties.DimY/2, z=self.Properties.DimZ/2 };
  101.     self:SetBBox( Min, Max );
  102.         
  103.     if(self.Properties.ExplosionEffect ~= "")then
  104.         self.explosion_effect = self.Properties.ExplosionEffect;
  105.     else
  106.         self.explosion_effect = "explosions.grenade_air.explosion";
  107.     end
  108.         
  109.     if(self.Properties.bInitiallyVisible==1)then
  110.         self:DrawObject(0,1);
  111.     else
  112.         self:DrawObject(0,0);
  113.     end
  114.  
  115.     self.bActive=self.Properties.bActive;
  116. end
  117.  
  118.  
  119. -------------------------------------------------------------------------------
  120. function PlaceableExplo:OnMultiplayerReset()
  121.     self:OnReset();
  122. end
  123.  
  124.  
  125. -------------------------------------------------------------------------------
  126. function PlaceableExplo:OnPropertyChange()
  127.     self:OnReset();
  128. end
  129.  
  130.  
  131. -------------------------------------------------------------------------------
  132.  
  133. function PlaceableExplo:PrintMessage(id,msg)
  134.     if(id)then
  135.         local slot=Server:GetServerSlotByEntityId(id)
  136.         if(slot)then
  137.             slot:SendText(msg,.9)
  138.         end
  139.     end
  140. end
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. ----------------------------------------------------
  150. --SERVER
  151. ----------------------------------------------------
  152. PlaceableExplo.Server={
  153.     OnInit=function(self)
  154.         self:LoadGeometry()
  155.         self:RegisterStates();
  156.         self:OnReset();
  157.         self:NetPresent(nil);
  158.     end,
  159. -------------------------------------
  160.     placeable={
  161.         OnBeginState=function(self)
  162.             self:DestroyPhysics();
  163.         end,
  164.         OnEnterArea = function(self,collider)
  165.             if(GameRules:IsInteractionPossible(collider,self))then
  166.                 if(collider.type=="Player" and (collider.cnt.health>0))then
  167.                     self.Who = collider;
  168.                     self:SetTimer(1);
  169.                 end
  170.             end        
  171.         end,
  172.         OnLeaveArea = function(self,collider)
  173.             if (collider == self.Who) then
  174.                 self.Who = nil;
  175.             end
  176.         end,
  177.         --------------------------------
  178.         OnTimer = function(self,dt)
  179.             if (self.Who) then
  180.                 self:Collide( self.Who );
  181.                 self:SetTimer(1);
  182.             end
  183.         end,
  184.     },
  185. -------------------------------------
  186.     notarmed={
  187.         OnBeginState=function(self)
  188.             self:DestroyPhysics();
  189.         end,
  190.     },
  191. -------------------------------------
  192.     armed={
  193.         OnBeginState=function(self)
  194.             self:DestroyPhysics();
  195.         end,
  196.         OnTimer=function(self)
  197.             -- [marco] it happens that the old timer is still set
  198.             -- from a previous state, if the player is colliding
  199.             if (self.Properties.countdown>=0) then
  200.                 if (self.countdown_step==0) then
  201.                     self:GotoState("detonated");
  202.                     BroadcastEvent( self,"Explode");
  203.                 else
  204.                 --    Hud:AddMessage(self.countdown_step.." seconds left",100);
  205.                     self:PrintMessage(self.target,self.countdown_step.." seconds left");
  206.                     self.countdown_step=self.countdown_step-1;
  207.                     self:SetTimer(1000); -- 1000 so the new message doesn't appear at the same time as an old messagge
  208.                 end
  209.             end
  210.         end,
  211.     },
  212. -------------------------------------
  213.     detonated={
  214.         OnBeginState=function(self)
  215.             if(self.Properties.object_ModelDestroyed~="")then
  216.                 self:CreateStaticEntity( 10,100 );
  217.             end
  218.         end,
  219.     },
  220. }
  221.  
  222. ----------------------------------------------------
  223. --CLIENT
  224. ----------------------------------------------------
  225. PlaceableExplo.Client={
  226.     OnInit=function(self)
  227.         self:LoadGeometry()
  228.         self:RegisterStates();
  229.         self.timing_sound=Sound:Load3DSound(self.timing_soundfile, 0, 255, 6, 45);
  230.         self:OnReset();
  231.         
  232.     end,
  233. -------------------------------------
  234.     placeable={
  235.         OnBeginState=function(self)
  236.             self:DrawObject(0,1);
  237.             self:DrawObject(1,0);
  238.             self:DrawObject(2,0);
  239.             self:DestroyPhysics();
  240.             Sound:StopSound(self.timing_sound);
  241.         end,
  242.     },
  243. -------------------------------------
  244.     notarmed={
  245.         OnBeginState=function(self)
  246.             self:DrawObject(0,0);
  247.             self:DrawObject(1,1);
  248.             self:DrawObject(2,0);
  249.             self:DestroyPhysics();
  250.             Sound:StopSound(self.timing_sound);
  251.         end,
  252.     },
  253. -------------------------------------
  254.     armed={
  255.         OnBeginState=function(self)
  256.             self:DrawObject(0,0);
  257.             self:DrawObject(1,1);
  258.             self:DrawObject(2,0);
  259.             self:DestroyPhysics();
  260.             --Sound:SetSoundPosition(self.timing_sound, self:GetPos());
  261.             self:PlaySound(self.timing_sound);
  262.             Sound:SetSoundLoop(self.timing_sound, 1);            
  263.         end,
  264.     },
  265. -------------------------------------
  266.     detonated={
  267.         OnBeginState=function(self)
  268.             self:Explode();
  269.             self:DrawObject(0,0);
  270.             self:DrawObject(1,0);
  271.             self:DrawObject(2,1);
  272.             Sound:StopSound(self.timing_sound);
  273.             if(self.Properties.object_ModelDestroyed~="")then
  274.                 self:CreateStaticEntity( 10,100 );
  275.             end
  276.         end,
  277.     },
  278. }
  279.  
  280.  
  281.  
  282.  
  283. -------------------------------------------------------------------------------
  284. function PlaceableExplo:Collide(player)
  285.  
  286.     -- [marco] player should not place explosives while driving
  287.     -- a vehicle
  288.     if ((player.type ~= "Player") or (player.theVehicle)) then return end
  289.  
  290.     if (self.bActive==0) then return end
  291.  
  292.     -- if the collider does have an explosive,
  293.     -- let's place it and remove it from the player
  294.  
  295.     for i,val in player.explosives do
  296.         if (val==1) then
  297.  
  298.             if (self.Properties.bAutomaticPlaceable~=1) then
  299.                 if (not player.cnt.use_pressed) then
  300.                     Hud.label=self.Properties.TextInstruction;
  301.                     do return end
  302.                 end
  303.             end
  304.  
  305.             player.explosives[i]=0;                
  306.             self.target=player.id
  307.             self:GotoState("armed");
  308.         
  309.             -- [marco] set countdown to 1 second and display a msg about
  310.             -- the countdown every second, repeat self.Properties.countdown times
  311.         
  312.             self.countdown_step=self.Properties.countdown;
  313.             --self:SetTimer(self.Properties.countdown*1000);
  314.     
  315.             -- [marco] needed by designers to activate explosion
  316.             -- by triggering something else after the explosive
  317.             -- has been placed
  318.             if (self.Properties.countdown>=0) then
  319.                 self:SetTimer(1000);
  320.             end
  321.         
  322.             self:Event_ExplosivePlaced();
  323.  
  324.             break;
  325.         end            
  326.     end    
  327. end
  328.  
  329. -------------------------------------------------------------------------------
  330. function PlaceableExplo:Event_Activate(sender)
  331.     self.bActive=1;
  332.     BroadcastEvent( self,"Activate");
  333. end
  334.  
  335. -------------------------------------------------------------------------------
  336. function PlaceableExplo:Event_DeActivateAndHide(sender)
  337.     self.bActive=0;
  338.     BroadcastEvent( self,"DeActivateAndHide");
  339.     self:Event_Hide();
  340. end
  341.  
  342. -------------------------------------------------------------------------------
  343. function PlaceableExplo:Event_ExplosivePlaced(sender)
  344.     BroadcastEvent( self,"ExplosivePlaced");
  345. end
  346.  
  347. -------------------------------------------------------------------------------
  348. function PlaceableExplo:Event_Explode(sender)
  349.     BroadcastEvent( self,"Explode" );
  350.     self:Explode();
  351. end
  352.  
  353. -------------------------------------------------------------------------------
  354. function PlaceableExplo:Event_Hide(sender)
  355.     self:DrawObject(0,0);
  356. end
  357.  
  358. -------------------------------------------------------------------------------
  359. function PlaceableExplo:Event_Show(sender)
  360.     self:DrawObject(0,1);
  361. end
  362.  
  363. -------------------------------------------------------------------------------
  364. function PlaceableExplo:Explode()
  365.  
  366.     local normal = { x=0,y=0,z=0.7 };
  367.     local pos = self:GetPos();
  368.     
  369.     Particle:SpawnEffect( pos,normal,self.explosion_effect,self.Properties.ExplosionScale );    
  370.     
  371.     self.explosion_params.pos = pos;
  372.     self.explosion_params.shooter=self;        
  373.  
  374.     self.explosion_params.damage =        self.Properties.explDamage;
  375.     self.explosion_params.rmin =         self.Properties.explRmin;
  376.     self.explosion_params.rmax =        self.Properties.explRmax;
  377.     self.explosion_params.radius =         self.Properties.explRadius;
  378.     self.explosion_params.impulsive_pressure = self.Properties.explImpulsive_pressure;
  379.  
  380.     Game:CreateExplosion(self.explosion_params);
  381.  
  382.     -- Trigger script command on explode.
  383.     if(self.Properties.ScriptCommand and self.Properties.ScriptCommand~="")then
  384.         --System:LogToConsole("Executing: "..self.Properties.ScriptCommand);
  385.         dostring(self.Properties.ScriptCommand);
  386.     end
  387.  
  388.     if(self.Properties.PlaySequence~="")then
  389.         Movie:PlaySequence( self.Properties.PlaySequence );
  390.     end
  391. end
  392.  
  393.  
  394.  
  395.  
  396.  
  397.